package com.pi.pro.xcmg.am.was.edi.led.service;





import com.pi.common.utils.TextUtils;
import com.pi.core.exchange.vo.NamedServiceProxy;
import com.pi.pro.xcmg.am.common.XcmgAmConstants;
import com.pi.pro.xcmg.am.common.vo.CommonExchangeResultData;
import com.pi.pro.xcmg.am.was.edi.led.dto.LedDefInfo;
import com.pi.pro.xcmg.am.was.edi.led.dto.LedErrorInfo;
import com.pi.pro.xcmg.am.was.edi.led.dto.LedTaskInfo;
import com.pi.pro.xcmg.am.was.edi.led.dto.R;
import com.pi.wms.fac.conn.HttpAccessUrl;
import com.pi.wms.fac.conn.HttpConstants;
import com.pi.wms.fac.conn.HttpclientProxy;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;


/**
 */
@Getter
@Setter
public class LedDisplayServiceProxy implements NamedServiceProxy {

    private String category;
    private String code;

    private HttpclientProxy ledDisplayClient;
    private HttpAccessUrl ledDisplayTextPostAccessUrl;
    private HttpAccessUrl ledTaskInfoPostAccessUrl;
    private HttpAccessUrl ledErrorInfoPostAccessUrl;
    private HttpAccessUrl ledDefInfoPostAccessUrl;

    /**
    public CommonExchangeResultData<String> execute(List<DisplayData> tasks) {
        CommonExchangeResultData<String> replyData=null;
        String replyText = "";
        if (this.ledDisplayClient==null){
            replyData = XcmgAmSupport.error("install client error");
            return replyData;
        }
        Map<String,String> headers = new HashMap<>();
        try{
            headers.put("Content-Type", XcmgAmConstants.HTTP_CONTENT_TYPE_HTTP_JSON);
            //
            replyText = this.ledDisplayClient.post(this.ledDisplayTextPostAccessUrl, null, headers,
                    HttpConstants.URL_METHOD_POST, TextUtils.toListJsonText(tasks));
            replyData= TextUtils.toObject(replyText, CommonExchangeResultData.class);
        }catch (Exception e){
            e.printStackTrace();
            replyText="send task report error.//"+e.getMessage();
            replyData= XcmgAmSupport.error(replyText);
        }
        return replyData;
    }
     **/

    public R<Void> showTaskInfo(LedTaskInfo taskInfo) {
        R<Void> replyData = null;
        String replyText = "";
        if (this.ledDisplayClient==null){
            return R.fail("install client error");
        }
        Map<String,String> headers = new HashMap<>();
        try{
            headers.put("Content-Type", XcmgAmConstants.HTTP_CONTENT_TYPE_HTTP_JSON);
            //
            replyText = this.ledDisplayClient.post(this.ledTaskInfoPostAccessUrl, null, headers,
                    HttpConstants.URL_METHOD_POST, TextUtils.toJsonText(taskInfo));
            replyData= TextUtils.toObject(replyText, R.class);
        }catch (Exception e){
            e.printStackTrace();
            R.fail("send task report error.//"+e.getMessage());
        }
        return replyData;
    }

    public R<Void> showErrorInfo(LedErrorInfo errorInfo) {
        R<Void> replyData = null;
        String replyText = "";
        if (this.ledDisplayClient == null) {
            return R.fail("install client error");
        }
        Map<String, String> headers = new HashMap<>();
        try {
            headers.put("Content-Type", XcmgAmConstants.HTTP_CONTENT_TYPE_HTTP_JSON);
            //
            replyText = this.ledDisplayClient.post(this.ledErrorInfoPostAccessUrl, null, headers,
                    HttpConstants.URL_METHOD_POST, TextUtils.toJsonText(errorInfo));
            replyData = TextUtils.toObject(replyText, R.class);
        } catch (Exception e) {
            e.printStackTrace();
            R.fail("send task report error.//" + e.getMessage());
        }
        return replyData;
    }

    public R<Void> showDefInfo(LedDefInfo defInfo) {
        R<Void> replyData = null;
        String replyText = "";
            if (this.ledDisplayClient == null) {
            return R.fail("install client error");
        }
        Map<String, String> headers = new HashMap<>();
        try {
            headers.put("Content-Type", XcmgAmConstants.HTTP_CONTENT_TYPE_HTTP_JSON);
            //
            replyText = this.ledDisplayClient.post(this.ledDefInfoPostAccessUrl, null, headers,
                    HttpConstants.URL_METHOD_POST, TextUtils.toJsonText(defInfo));
            replyData = TextUtils.toObject(replyText, R.class);
        } catch (Exception e) {
            e.printStackTrace();
            R.fail("send task report error.//" + e.getMessage());
        }
        return replyData;
    }
}